package com.eryos.gwt.estate.client.place;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;

/**
 * A place is a Java object representing a particular state of the UI. A Place can be converted to and from a URL
 * history token by defining a PlaceTokenizer for each Place, and GWT's PlaceHistoryHandler automatically updates the
 * browser URL corresponding to each Place.
 * 
 * @author combeol
 * @version $Revision$
 */
public class ErrorPlace extends Place {

    private final String placeName;
    private final Exception exception;

    /************ attribute_list ************/

    /************ Constructors ************/
    public ErrorPlace(String token) {
        this.placeName = token;
        this.exception = null;
    }

    public ErrorPlace(String token, Exception exc) {
        this.placeName = token;
        this.exception = exc;
    }

    public String getPlaceName() {
        return placeName;
    }

    /************ Getters ************/

    /**
     * @return the exception
     */
    public Exception getException() {
        return exception;
    }

    /**
     * PlaceTokenizer is not needed for each Place. Many Places might not save any state to the URL, so they could
     * just extend a BasicPlace which declares a PlaceTokenizer that returns a null token.
     */
    public static class Tokenizer implements PlaceTokenizer<ErrorPlace> {
        @Override
        public String getToken(ErrorPlace place) {
            return place.getPlaceName();
        }

        @Override
        public ErrorPlace getPlace(String token) {
            return new ErrorPlace(token);
        }
    }

}
